<?php
/**
 *
 * @Author 夸克
 * @Email 79517721@qq.com
 * @Description //广告接口 只需要输出 文字、标题链接、图片地址
 *                如果
 * @Date
 * @Version 1.0
 * @WebSite www.dashubaba.com
 * @AllRight 大树巴巴科技开发团队
 *
 **/

include "./ad/app/common.php";

$today = date("Y-m-d");

$where = " where is_show = 1 ";

//大横幅
$bigAdList = $ADDB->query("SELECT t.*,curdate() as today FROM ad_big t $where  order by sort asc")->fetchAll();

$bigAdListData = [];
//如果没到期那就显示广告，到期了就显示默认的文字 图片 链接
for ($i=0;$i<count($bigAdList);$i++){
    if($today > $bigAdList[$i]['end_time']){//广告到期了
        $bigAdListData[$i]['ad_img'] = $bigAdList[$i]['default_img'];
        $bigAdListData[$i]['ad_url'] = "/ad/buyAd.php?buy="._encrypt($bigAdList[$i]['id']."|||big",SYS_KEY);
    }else{
        $bigAdListData[$i]['ad_img'] = $bigAdList[$i]['ad_img'];
        //$bigAdListData[$i]['ad_url'] = _encrypt($bigAdList[$i]['ad_url'],SYS_KEY);
        $bigAdListData[$i]['ad_url'] = $bigAdList[$i]['ad_url'];
    }

}


//小横幅
$smallAdList = $ADDB->query("SELECT t.*,curdate() as today FROM ad_small t $where  order by sort asc")->fetchAll();

$smallAdListData = [];
//如果没到期那就显示广告，到期了就显示默认的文字 图片 链接
for ($i=0;$i<count($smallAdList);$i++){
    if($today > $smallAdList[$i]['end_time']){//广告到期了
        $smallAdListData[$i]['ad_img'] = $smallAdList[$i]['default_img'];
        $smallAdListData[$i]['ad_url'] = "/ad/buyAd.php?buy="._encrypt($smallAdList[$i]['id']."|||small",SYS_KEY);
    }else{
        $smallAdListData[$i]['ad_img'] = $smallAdList[$i]['ad_img'];
        $smallAdListData[$i]['ad_url'] = $smallAdList[$i]['ad_url'];
        //$smallAdListData[$i]['ad_url'] = _encrypt($smallAdList[$i]['ad_url'],SYS_KEY);
    }

}

//文字

$wordAdList = $ADDB->query("SELECT t.*,curdate() as today FROM ad_word t $where  order by sort asc")->fetchAll();

$wordAdListData = [];
//如果没到期那就显示广告，到期了就显示默认的文字 图片 链接
for ($i=0;$i<count($wordAdList);$i++){
    if($today > $wordAdList[$i]['end_time']){//广告到期了
        $wordAdListData[$i]['ad_title'] = $wordAdList[$i]['default_title'];
        $wordAdListData[$i]['ad_url'] = "/ad/buyAd.php?buy="._encrypt($wordAdList[$i]['id']."|||word",SYS_KEY);
    }else{
        $wordAdListData[$i]['ad_title'] = $wordAdList[$i]['ad_title'];
        //$wordAdListData[$i]['ad_url'] = _encrypt($wordAdList[$i]['ad_url'],SYS_KEY);
        $wordAdListData[$i]['ad_url'] = $wordAdList[$i]['ad_url'];

    }
    $wordAdListData[$i]['ad_background'] = $wordAdList[$i]['ad_background'];
    $wordAdListData[$i]['ad_text_color'] = $wordAdList[$i]['ad_text_color'];
}

